mod init {
    pub(super) unsafe fn init() {
        println!("init before main");
    }
}

unsafe extern "C" fn init_args(argc: i32, argv: *const *const i8) {
    println!("argc = {argc}, program = {:?}", std::ffi::CStr::from_ptr(*argv));
}

#[cfg(target_os = "linux")]
unsafe extern "C" fn init_args_envs(argc: i32, argv: *const *const i8, envs: *const *const i8) {
    println!("argc = {argc}, program = {:?} env.0 = {:?}", std::ffi::CStr::from_ptr(*argv), std::ffi::CStr::from_ptr(*envs));
}

use init::init;
hictor::ctor!(init_mod, init);
hictor::ctor_args!(init_args);

#[cfg(target_os = "linux")]
hictor::ctor_custom!(init_args_envs);

hictor::dtor!(fini_env);

unsafe fn fini_env() {
    println!("fini after main");
}

fn main() {
    println!("program_name: {}, short_name: {}, hello hictor", hictor::program_invocation_name(), hictor::program_invocation_short_name());
}
